package com.ruoyi.framework.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.List;

@Slf4j
@Component
public class RequestLoggingInterceptor implements HandlerInterceptor {
    private static final List<String> IGNORE_PATHS = List.of(
            "/webjars",
            "/v3/api-docs",
            "/swagger-resources",
            "/doc.html",
            "/favicon.ico"
    );

    private boolean isLoggableRequest(String uri) {
        return IGNORE_PATHS.stream().noneMatch(uri::startsWith);
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String uri = request.getRequestURI();
        if (isLoggableRequest(uri)) {
            log.info("收到 {} 请求( ﹡ˆoˆ﹡ )： {}", request.getMethod(), uri);
        }
        // 放行请求
        return true;
    }
}